// 数组去重
export const unique1 = arr => {
  return [...new Set(arr)];
};
// 数组对象去重
export const objArrDemp1 = (objArr, para) => {
  const result = [];
  const temp = {};
  for (let i = 0; i < objArr.length; i++) {
    const parameter = objArr[i][para];
    if (temp[parameter]) {
      continue;
    }
    temp[parameter] = true;
    result.push(objArr[i]);
  }
  return result;
};
// 统计字符串或数组中各个元素出现的次数
export const strArrNum = para => {
  let arr = [];
  para instanceof Array ? (arr = para) : (arr = para.split(''));
  return arr.reduce((p, v) => {
    if (p[v]) {
      p[v] += 1;
    } else {
      p[v] = 1;
    }
    return p;
  }, {});
};
// 在数组中找指定的元素,返回下标
export const arrFinNum = (arr, num) => {
  return arr.indexOf(num);
};

// 删除数组中的元素
export const delArrNum = (arr, val) => {
  const index = arr.indexOf(val);
  if (index !== -1) {
    return arr.splice(index, 1);
  }
};
// 对象处理为数组对象
export const objToArrObj = obj => {
  const arr = [];
  for (const i in obj) {
    arr.push({ [i]: obj[i] });
  }
  return arr;
};
